﻿using System;
using Nuwanda.Common;
using Nuwanda.TfsSpotlight.Shell;
using Nuwanda.TfsSpotlight.Shell.Services.Interfaces;
using Nuwanda.TfsSpotlight.Views.Servers;
using StructureMap;

namespace Nuwanda.TfsSpotlight.Commands
{
    /// <summary>Closes the application</summary>
    [Author("Bartłomiej Legiędź")]
    [Pluggable(CommandsNames.ExitApplication)]
    public class ExitApplicationCommand : ICommand
    {
        private IApplicationController ApplicationController{ get; set; }
        private ITabsService TabsService { get; set; }
        private IServersPresenter ServersPresenter { get; set; }

        public ExitApplicationCommand(
            IApplicationController applicationController, ITabsService tabsService, IServersPresenter serversPresenter)
        {
            this.ApplicationController = applicationController;
            TabsService = tabsService;
            ServersPresenter = serversPresenter;
        }

        public void Execute()
        {
            this.ApplicationController.SaveLayoutSate();
            this.TabsService.CloseAllTabs();
            this.ServersPresenter.HandleDisconnectAll();

            Environment.Exit(0);
        }
    }
}